package view.sprite;

import com.trolltech.qt.core.QPoint;
import com.trolltech.qt.core.QRect;
import com.trolltech.qt.gui.QImage;

public class BaseSprite {

	protected QImage currImage;
	protected QPoint position;
	private QRect rect;
	

	public QImage getCurrImage() {
		return currImage;
	}

	public void setCurrImage(final QImage currImage) {
		this.currImage = currImage;
	}

	public QPoint getPosition() {
		return position;
	}
	public void setPosition(final QPoint position) {
		this.position = position;
	}

	public QRect getRect() {
		return rect;
	}

	public void setRect(QRect rect) {
		this.rect = rect;
	}

	public void setRect(final int w,final int h, final int maxDim){
			
			final int minSize = Math.min(w, h);
			
			final int distx= minSize * 1/maxDim;
			final int disty= minSize * 1/maxDim;
			
			final double x =(double)position.x()/maxDim;
			final double y =(double)position.y()/maxDim;
					
			final QPoint topleft = new QPoint();
			
			topleft.setX( (int) (x * (minSize)+ (w-minSize)/2 ));
			topleft.setY( (int) (y * (minSize)+ (h-minSize)/2 ));
			
	//		System.out.println(position.x()+","+position.y()+" -> "+topleft.x()+","+topleft.y());
			
			final QPoint bottomright = new QPoint();
			bottomright.setX(topleft.x()+distx);
			bottomright.setY(topleft.y()+disty);
					
			this.rect = new QRect(topleft , bottomright);
		}

	@Override
	public String toString() {
		return "BaseSprite [position=" + position + ", rect=" + rect + "]";
	}

	
	
}
